package com.blog.admin.controller;

import com.blog.admin.pojo.Admin;
import com.blog.admin.service.AdminService;
import com.blog.common.vo.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpCookie;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/api/rest/admin")
public class AdminController {

    @Autowired
    private AdminService adminService;

    @PostMapping("/login")
    public JsonResult loginAdmin(@RequestBody Admin admin){
        return adminService.login(admin);
    }

    @PostMapping("/info")
    public JsonResult adminInfo(@RequestBody Map<String,String> token , HttpServletRequest request){
        return adminService.getInfo(token.get("token"));
    }

    @PostMapping("/updateinfo")
    public JsonResult updateInfo(@RequestBody Admin admin){
        return adminService.saveOrUpdateAdmin(admin);
    }
}
